package com.axs.camera.remote;


import android.util.Log;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitManager {
    private static volatile RetrofitManager sInstance;
    private Retrofit mRetrofit;
    private OkHttpClient mOkHttpClient;

    public static final String TOKEN = "24.9195abdfd1c4e534c2451d12bcd4e8e3.2592000.1649417365.282335-25730148";

    private RetrofitManager() {
        mOkHttpClient = new OkHttpClient.Builder()
                .addNetworkInterceptor(mLoggingInterceptor)
                .build();

        mRetrofit = new Retrofit.Builder()
                .baseUrl("https://aip.baidubce.com/")
                .client(mOkHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }

    private HttpLoggingInterceptor mLoggingInterceptor = new HttpLoggingInterceptor(s -> {
        Log.d("Request", s);
    }).setLevel(HttpLoggingInterceptor.Level.BODY);

    public static RetrofitManager getInstance() {
        if (sInstance == null) {
            synchronized (RetrofitManager.class) {
                if (sInstance == null) {
                    sInstance = new RetrofitManager();
                }
            }
        }
        return sInstance;
    }

    public Retrofit getRetrofit() {
        return mRetrofit;
    }
}
